package com.ruoyi.order.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.order.api.domain.TPayLog;
import com.ruoyi.order.service.ITPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 支付日志Controller
 *
 * @author chengyujie
 * @date 2023-09-22
 */
@RestController
@RequestMapping("/log")
public class TPayLogController extends BaseController {
    @Autowired
    private ITPayLogService tPayLogService;

    /**
     * 查询支付日志列表
     */
    @RequiresPermissions("order:log:list")
    @GetMapping("/list")
    public TableDataInfo list(TPayLog tPayLog) {
        startPage();
        List<TPayLog> list = tPayLogService.selectTPayLogList(tPayLog);
        return getDataTable(list);
    }

    /**
     * 导出支付日志列表
     */
    @RequiresPermissions("order:log:export")
    @Log(title = "支付日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPayLog tPayLog) {
        List<TPayLog> list = tPayLogService.selectTPayLogList(tPayLog);
        ExcelUtil<TPayLog> util = new ExcelUtil<TPayLog>(TPayLog.class);
        util.exportExcel(response, list, "支付日志数据");
    }

    /**
     * 获取支付日志详细信息
     */
    @RequiresPermissions("order:log:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tPayLogService.selectTPayLogById(id));
    }

    /**
     * 修改支付日志
     */
    @RequiresPermissions("order:log:edit")
    @Log(title = "支付日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPayLog tPayLog) {
        return toAjax(tPayLogService.updateTPayLog(tPayLog));
    }

    /**
     * 删除支付日志
     */
    @RequiresPermissions("order:log:remove")
    @Log(title = "支付日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tPayLogService.deleteTPayLogByIds(ids));
    }
}
